import { axiosInstance } from 'src/boot/axios'
import CommonConfig from '../../assets/js/config'
import qs from 'qs'

const reportUrl = CommonConfig.reportUrl + '/v1'
const qsConfig = {
  arrayFormat: 'repeat',
  skipNulls: true,
  format: 'RFC3986'
}
export function getAvailabilityList (query) {
  const params = {
    startDate: query.startDate,
    endDate: query.endDate,
    startHour: query.startHour,
    endHour: query.endHour,
    type: query.type,
    deviceTreeReqVO: query.deviceTreeReqVO
  }
  const newUrl = reportUrl + '/oee_a_pc_reports'
  return axiosInstance.post(newUrl, params).then((res) => {
    return Promise.resolve((res))
  })
}

// v1/cutter_use/list_cutter_use
// 列举刀具使用报表
export function getListCutterUse ({
  bindingTime1, bindingTime2, borrowTime1, borrowTime2, cutterModel, cutterNo, cutterType, pageNum, pageSize, returnTime1, returnTime2, unbindingTime1, unbindingTime2, productName
}) {
  const params = {
    bindingTime1, bindingTime2, borrowTime1, borrowTime2, cutterModel, cutterNo, cutterType, pageNum, pageSize, returnTime1, returnTime2, unbindingTime1, unbindingTime2, productName
  }
  let reqData = {
    params,
    paramsSerializer: function (params) {
      return qs.stringify(params, qsConfig)
    }
  }
  const newUrl = reportUrl + '/cutter_use/list_cutter_use'
  return axiosInstance.get(newUrl, reqData).then((res) => {
    return Promise.resolve((res.data))
  })
}

// /v1/cutter_use/export_cutter_use
// 导出刀具使用报表
export function getCutterReportExport ({ bindingTime1, bindingTime2, borrowTime1, borrowTime2, cutterModel, cutterNo, cutterType, pageNum, pageSize, returnTime1, returnTime2, unbindingTime1, unbindingTime2
  , requestId }) {
  const newUrl = reportUrl + '/cutter_use/export_cutter_use'
  let reqData = {
    params: {
      bindingTime1,
      bindingTime2,
      borrowTime1,
      borrowTime2,
      cutterModel,
      cutterNo,
      cutterType,
      pageNum,
      pageSize,
      returnTime1,
      returnTime2,
      unbindingTime1,
      unbindingTime2,
      requestId
    },
    paramsSerializer: function (params) {
      return qs.stringify(params, qsConfig)
    }
  }
  return axiosInstance.get(newUrl, reqData).then((res) => {
    return Promise.resolve(res)
  })
}
